/**
 * 
 */
package game;


import java.util.ArrayList;

import chess.Board;
import chess.Player;

import view.View;
/**
 * @author Max Joyce (Jan 22,2010)
 *
 */
public abstract class Game {
	
	private Board board;
	public MoveExecutionList listOfMoves;
	protected View view;
	protected boolean isNewGame;

	/**
	 * Constructor for generic games
	 * <pre>
	 * Max Joyce
	 * -Creation (Jan 21,2010)
	 * Caleb Chan
	 * -Added view to constructor.  Default is a console view (Feb 9, 2010)
	 * </pre>
	 */
	public Game() {
		board = new Board(this);
		listOfMoves = new MoveExecutionList();
		isNewGame = false;
		// TODO Auto-generated constructor stub
		
	}

	public void setView(View view){
		this.view = view;
	}
	/**
	 * Determines whether or not the game is over
	 * <pre>
	 * Max Joyce
	 * -Creation (Jan 21,2010)
	 * </pre>
	 */
	public boolean gameOver() {
		return false;
	}

	 /**
	  * This function will allow you to choose a tile.
	  * 
	  * <pre>
	  * Max Joyce
	  * -Creation (Jan 21,2010)
	  * Caleb Chan
	  * - fixed error of user only entering 1 digit as a coordinate and numbers greater then 
	  * 	size of the board
	  * - chooseTile method will keep looping until valid coordinate is entered
	  * - Pulled chooseTile up to be determined by the current view. (Feb 9,2010)
	  * </pre>
	  * @return The tile being chosen
	  */
	public chess.Tile chooseTile() {
		return view.chooseTile();
	}
	/**
	 * This method will return the list of moves  
	 * @return Returns the list of moves
	 */
	public MoveExecutionList getMoveExecutionList(){
		return listOfMoves;
	}
	/**
	 * This functions returns the game board
	 * 
	 * <pre>
	 * Max Joyce
	 * -Creation (Jan 21,2010)
	 * </pre>
	 * 
	 * @return Returns the game board
	 */
	public Board getBoard() {
		return board;
	}
	/**
	 * This method returns the display of the view
	 * <pre>
	 * Caleb Chan
	 * -Creation (Feb 9,2010)
	 * </pre>
	 * @return The view being used by the game
	 */
	public View getView(){
		return view;
	}

	/**
	 * This will allow you to play your game.
	 * 
	 * <pre>
	 * Max Joyce
	 * -Creation (Jan 22,2010)
	 * </pre>
	 */	
	public abstract void play();
	
	/**
	 * This function will set up the game to be played.  A default game such as
	 * this should have no specific definition
	 * <pre>
	 * Max Joyce
	 * -Creation (Jan 21,2010)
	 * </pre>
	 */
	public abstract void startup();

	/**
	 * This defines the turn for a human player
	 * <pre>
	 * Max Joyce
	 * -Creation (Feb 9, 2010)
	 * </pre>
	 * @param p The player who is taking the turn
	 */
	public abstract void takeTurn(Player p);
	/**
	 * This will handle all task before a new game can be created
	 */
	public abstract void newGameSelected();
	/**
	 * This will handle the redo that is game specific
	 */
	public abstract void redo();
	/**
	 * This will handle the undo that is game specific
	 */
	public abstract void undo();
	/**
	 * This will set the player by the index. 
	 * @param player The index of the player in the current list of players
	 */
	public abstract void setPlayer(int player);
	/**
	 * This method will get the players in the game
	 * @return Returns a list of players
	 */
	public abstract ArrayList<Player> getPlayers();

	/**
	 * This method will set the list of moves and it is used when importing a move list. 
	 * If the board has a game currenly active, it will reset the board.
	 * @param list The move list that is being replaced
	 * <pre>
	 * Caleb Chan
	 * </pre>
	 */
	public void setMoveList(MoveExecutionList list) {
		this.listOfMoves = list;
	}

	/**
	 * This method will reset the board to the start position
	 * <pre>
	 * Caleb Chan
	 * </pre>
	 */
	public void resetBoard() {
		while(listOfMoves.undo());
	}
	public void restoreBoard(){
		while(listOfMoves.redo());
	}
}
